<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改合集管理')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-collection-edit" th:object="${cmsCollection}">
            <input name="id" th:field="*{id}" type="hidden">

            
      
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">栏目：</label>
                <div class="col-sm-8">
                    <div class="input-group"  onclick="selectCollectioncategoryTree()">
                        <input id="treeId" name="categoryId" type="hidden" th:field="*{categoryId}" />
                        <input class="form-control" type="text"  id="treeName" readonly="true" th:field="*{categoryName}" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>                
            
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">标题：</label>
                <div class="col-sm-8">
                    <input name="title" th:field="*{title}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">标签：</label>
                <div class="col-sm-8">
                    <textarea name="tags" class="form-control">[[*{tags}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">模块类型：</label>
                <div class="col-sm-8">
                    <select name="dictModuleType" class="form-control m-b" th:with="type=${@dict.getType('dict_module_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{dictModuleType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">推荐位：</label>
                <div class="col-sm-8">
                    <select name="dictPostPositions" class="form-control m-b" th:with="type=${@dict.getType('dict_post_positions')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{dictPostPositions}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">展示策略：</label>
                <div class="col-sm-8">
                    <select name="dictShowStrategy" class="form-control m-b" th:with="type=${@dict.getType('dict_show_strategy')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{dictShowStrategy}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">会员策略：</label>
                <div class="col-sm-8">
                    <select name="dictVipStrategy" class="form-control m-b" th:with="type=${@dict.getType('dict_vip_strategy')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{dictVipStrategy}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">市场价：</label>
                <div class="col-sm-8">
                    <input name="maxPrice" th:field="*{maxPrice}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">销售价：</label>
                <div class="col-sm-8">
                    <input name="price" th:field="*{price}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">销售数量：</label>
                <div class="col-sm-8">
                    <input name="saleNumber" th:field="*{saleNumber}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">外部链接：</label>
                <div class="col-sm-8">
                    <textarea name="href" class="form-control">[[*{href}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">标题颜色：</label>
                <div class="col-sm-8">
                    <input name="color" th:field="*{color}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">封面：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="image" th:field="*{image}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="image" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">关键字：</label>
                <div class="col-sm-8">
                    <textarea name="keywords" class="form-control">[[*{keywords}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">描述：</label>
                <div class="col-sm-8">
                    <textarea name="description" class="form-control">[[*{description}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">点击数：</label>
                <div class="col-sm-8">
                    <input name="hits" th:field="*{hits}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">收藏数：</label>
                <div class="col-sm-8">
                    <input name="collectionCount" th:field="*{collectionCount}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">字数：</label>
                <div class="col-sm-8">
                    <input name="wordCount" th:field="*{wordCount}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">内容视图：</label>
                <div class="col-sm-8">
                    <select name="dictContentView" class="form-control m-b" th:with="type=${@dict.getType('dict_content_view')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{dictContentView}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">视图配置：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" th:field="*{dictViewConfig}">
                    <div class="summernote" id="dictViewConfig"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sort" th:field="*{sort}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注信息：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "ecms/collection";
        $("#form-collection-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-collection-edit').serialize());
            }
        }

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    dialogsInBody: true,
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/upload",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });
    </script>
	<script type="text/javascript">
	
	/*栏目分类-新增-选择父栏目分类树*/
	function selectCollectioncategoryTree() {
	    var options = {
	        title: '栏目分类选择',
	        width: "380",
	        url: ctx + "ecms/collectioncategory" + "/selectCollectioncategoryTree/" + $("#treeId").val(),
	        callBack: doSubmit
	    };
	    $.modal.openOptions(options);
	}
	
	function doSubmit(index, layero){
	    var body = $.modal.getChildFrame(index);
	    $("#treeId").val(body.find('#treeId').val());
	    $("#treeName").val(body.find('#treeName').val());
	    $.modal.close(index);
	}
	</script>        
    
</body>
</html>